#ifndef STRINGLISTMODEL_H
#define STRINGLISTMODEL_H

#include <QAbstractListModel>
#include <QModelIndex>
#include <QVariant>
#include <QStringList>

class StringListModel : public QAbstractListModel
{
    Q_OBJECT
public:
    StringListModel (const QStringList& strigns, QObject* parent = 0);
    // explicit StringListModel(const QStringList& strings, QObject *parent = nullptr);

    int rowCount(const QModelIndex& parent = QModelIndex()) const;

    // 注意虚函数是的参数是下面的写法的哦，int 类型的参数是在后面的哦。不然会爆下面的 error 的
    // error: main.cpp:19:21: Variable type 'StringListModel' is an abstract class 并且 qabstractitemmodel.h:191:34: unimplemented pure virtual method 'data' in 'StringListModel'
    // QVariant data(int role, const QModelIndex& index) const;
    QVariant data(const QModelIndex& index, int role) const;

    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;

    // 设置可编辑选项
    Qt::ItemFlags flags(const QModelIndex& index) const;

    bool setData(const QModelIndex& index, const QVariant& value, int role);

    // 添加行与删除行
    bool insertRows(int position, int rows, const QModelIndex& index = QModelIndex());

    bool removeRows(int position, int rows, const QModelIndex& index = QModelIndex());

private:
    QStringList stringlist;
};

#endif // STRINGLISTMODEL_H
